﻿using Business;
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace UI.Areas.Admin.Controllers
{
    
    public class HomeController : Controller
    {
        // GET: Admin/Home
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult HomePage()
        {
            ViewBag.IP = StringHelper.GetUserIP();
            return View();
        }
        [AllowAnonymous]
        public ActionResult Login()
        {
            return View();
        }
        [AllowAnonymous]
        [HttpPost]
        public JsonResult Login(string username, string pwd)
        {
            httpModel t_result = new httpModel() { status = DoResult.Success };
            PAY_ADMIN t_pay_admin = new PAY_ADMIN().SelectByObj($"adminname='{username}' and adminpass='{StringHelper.MD5(pwd)}'");
            if (t_pay_admin == null)
            {
                t_result.status = DoResult.Failed;
                t_result.msg = "账号或密码不正确";
            }
            Session["CurrentUser"] = t_pay_admin;
            if (this.HttpContext.Session["CurrentUrl"] == null)
            {
                t_result.data = "/Admin/";
            }
            else
            {
                string url = this.HttpContext.Session["CurrentUrl"].ToString();
                this.HttpContext.Session["CurrentUrl"] = null;
                t_result.data = url;
            }
            return Json(t_result, JsonRequestBehavior.AllowGet);
        }
        [AllowAnonymous]
        //退出登陆
        public ActionResult LogOut()
        {
            Session["CurrentUser"] = null;
            return View("Login");
        }
    }
}